import React, { useState, useEffect } from "react";
import {
  Card,
  Table,
  Button,
  Space,
  Tag,
  Modal,
  Form,
  Input,
  Select,
  DatePicker,
  message,
  Row,
  Col,
  Statistic,
  Progress,
  Tabs,
  Typography,
  Tooltip,
  Badge,
  Popconfirm,
  Alert,
  List,
  Avatar,
  Divider,
  Steps,
  Switch,
  TimePicker,
  InputNumber,
  Upload,
  Drawer,
  Descriptions,
  Rate,
  Empty,
  Spin,
  Dropdown,
  Menu,
} from "antd";
import {
  PlusOutlined,
  EditOutlined,
  DeleteOutlined,
  EyeOutlined,
  SendOutlined,
  DownloadOutlined,
  UploadOutlined,
  FileTextOutlined,
  ClockCircleOutlined,
  TeamOutlined,
  TrophyOutlined,
  CheckCircleOutlined,
  ExclamationCircleOutlined,
  SearchOutlined,
  FilterOutlined,
  ExportOutlined,
  ImportOutlined,
  SettingOutlined,
  StarOutlined,
  BarChartOutlined,
  ReloadOutlined,
  MoreOutlined,
  CopyOutlined,
  ShareAltOutlined,
  LockOutlined,
  UnlockOutlined,
  CalendarOutlined,
  UserOutlined,
  BookOutlined,
  CheckOutlined,
  CloseOutlined,
  SyncOutlined,
  RobotOutlined,
  AuditOutlined,
  RollbackOutlined,
  MessageOutlined,
  LoadingOutlined,
} from "@ant-design/icons";
import type { ColumnsType } from "antd/es/table";
import type { UploadFile } from "antd/es/upload/interface";
import dayjs from "dayjs";
import { useNavigate } from "react-router-dom";
import { generateMockPapers, generateMockExams, generateMockSubmissions, getExamStatistics } from "../../../utils/examMockData";
import { examStore } from "../../../utils/examStore";
import { COURSES, CLASSES } from "../../../utils/mockData";

const { Search } = Input;
const { TextArea } = Input;
const { Option } = Select;
const { Title, Text, Paragraph } = Typography;
const { TabPane } = Tabs;
const { Step } = Steps;
const { RangePicker } = DatePicker;

// 试卷接口
interface ExamPaper {
  id: string;
  name: string;
  code: string;
  courseId: string;
  courseName: string;
  totalScore: number;
  duration: number; // 分钟
  questionCount: number;
  difficulty: "简单" | "中等" | "困难";
  status: "draft" | "published" | "archived";
  createTime: string;
  updateTime: string;
  creator: string;
  description?: string;
  tags: string[];
  isTemplate: boolean;
  usageCount: number;
  averageScore?: number;
  passRate?: number;
}

// 考试接口
interface Exam {
  id: string;
  name: string;
  paperId: string;
  paperName: string;
  courseId: string;
  courseName: string;
  startTime: string;
  endTime: string;
  duration: number; // 分钟
  status: "draft" | "published" | "ongoing" | "ended" | "graded";
  totalStudents: number;
  submittedCount: number;
  gradedCount: number;
  averageScore?: number;
  passRate?: number;
  createTime: string;
  publishTime?: string;
  selectedClasses: string[]; // 选中的班级ID
  selectedCourses: string[]; // 选中的课程ID
  settings: {
    allowLateSubmission: boolean;
    maxLateMinutes: number;
    allowReview: boolean;
    autoGrade: boolean;
    requireProctor: boolean;
  };
}

// 考试提交接口
interface ExamSubmission {
  id: string;
  examId: string;
  examName: string;
  studentId: string;
  studentName: string;
  className: string;
  submitTime: string;
  status: "submitted" | "graded" | "published" | "late";
  score?: number;
  totalScore: number;
  timeSpent: number; // 分钟
  gradedBy?: string;
  gradedTime?: string;
  comments?: string;
  aiScore?: number;
  aiComments?: string;
  teacherScore?: number;
  teacherComments?: string;
}

const ExamManagement: React.FC = () => {
  const navigate = useNavigate();
  const [activeTab, setActiveTab] = useState("papers");
  const [loading, setLoading] = useState(false);
  const [searchText, setSearchText] = useState("");
  const [statusFilter, setStatusFilter] = useState<string>("all");
  const [courseFilter, setCourseFilter] = useState<string>("all");
  
  // 试卷管理状态
  const [papers, setPapers] = useState<ExamPaper[]>([]);
  const [selectedPaper, setSelectedPaper] = useState<ExamPaper | null>(null);
  const [paperDetailVisible, setPaperDetailVisible] = useState(false);
  const [createPaperModalVisible, setCreatePaperModalVisible] = useState(false);
  const [editPaperModalVisible, setEditPaperModalVisible] = useState(false);
  
  // 考试管理状态
  const [exams, setExams] = useState<Exam[]>([]);
  const [selectedExam, setSelectedExam] = useState<Exam | null>(null);
  const [examDetailVisible, setExamDetailVisible] = useState(false);
  const [createExamModalVisible, setCreateExamModalVisible] = useState(false);
  const [publishExamModalVisible, setPublishExamModalVisible] = useState(false);
  
  // 成绩管理状态
  const [submissions, setSubmissions] = useState<ExamSubmission[]>([]);
  const [selectedSubmission, setSelectedSubmission] = useState<ExamSubmission | null>(null);
  const [gradingModalVisible, setGradingModalVisible] = useState(false);
  const [batchGradingModalVisible, setBatchGradingModalVisible] = useState(false);
  
  // 表单状态
  const [paperForm] = Form.useForm();
  const [examForm] = Form.useForm();
  const [gradingForm] = Form.useForm();

  // 初始化数据
  useEffect(() => {
    loadData();
  }, []);

  const loadData = async () => {
    setLoading(true);
    try {
      // 模拟API调用
      await new Promise(resolve => setTimeout(resolve, 1000));
      setPapers(examStore.getPapers());
      setExams(examStore.getExams());
      setSubmissions(examStore.getSubmissions());
    } catch (error) {
      message.error("加载数据失败");
    } finally {
      setLoading(false);
    }
  };

  // 试卷管理相关函数
  const handleCreatePaper = () => {
    setCreatePaperModalVisible(true);
  };

  const handleEditPaper = (paper: ExamPaper) => {
    setSelectedPaper(paper);
    paperForm.setFieldsValue({
      name: paper.name,
      code: paper.code,
      courseId: paper.courseId,
      totalScore: paper.totalScore,
      duration: paper.duration,
      difficulty: paper.difficulty,
      description: paper.description,
      tags: paper.tags,
    });
    setEditPaperModalVisible(true);
  };

  const handleDeletePaper = (paperId: string) => {
    Modal.confirm({
      title: "确认删除",
      content: "确定要删除这份试卷吗？删除后无法恢复。",
      onOk: () => {
        setPapers(prev => prev.filter(p => p.id !== paperId));
        message.success("试卷删除成功");
      },
    });
  };

  // 导出试卷
  const handleExportPaper = (paper: ExamPaper) => {
    Modal.confirm({
      title: (
        <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
          <ExclamationCircleOutlined style={{ color: '#faad14' }} />
          <span>导出试卷</span>
        </div>
      ),
      content: "请选择导出方式：",
      cancelText: "取消",
      onCancel: () => Modal.destroyAll(),
      footer: [
        <Button key="cancel" onClick={() => Modal.destroyAll()}>
          取消
        </Button>,
        <Button 
          key="save" 
          type="primary" 
          onClick={() => {
            message.success("试卷已保存到考试管理！");
            Modal.destroyAll();
          }}
          style={{ marginRight: '8px' }}
        >
          保存到考试管理
        </Button>,
        <Button 
          key="export" 
          onClick={() => {
            // 模拟PDF导出过程
            message.loading("正在生成PDF文件...", 2).then(() => {
              // 创建下载链接
              const blob = new Blob([`试卷内容：${paper.name}\n总分：${paper.totalScore}\n时长：${paper.duration}分钟\n题目数：${paper.questionCount}`], { 
                type: 'application/pdf' 
              });
              const url = window.URL.createObjectURL(blob);
              const link = document.createElement('a');
              link.href = url;
              link.download = `${paper.name}.pdf`;
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);
              window.URL.revokeObjectURL(url);
              
              message.success("试卷导出成功！文件已保存到下载文件夹");
              Modal.destroyAll();
            });
          }}
        >
          导出文件
        </Button>,
      ],
    });
  };

  // 考试管理相关函数
  const handleCreateExam = () => {
    setCreateExamModalVisible(true);
  };

  const handlePublishExam = (exam: Exam) => {
    setSelectedExam(exam);
    setPublishExamModalVisible(true);
  };

  const handleCreateExamSubmit = (values: any) => {
    const newExam = examStore.addExam({
      name: values.name,
      paperId: values.paperId,
      paperName: papers.find(p => p.id === values.paperId)?.name || "",
      courseId: values.courseId,
      courseName: values.courseName,
      startTime: values.startTime.format("YYYY-MM-DD HH:mm:ss"),
      endTime: values.endTime.format("YYYY-MM-DD HH:mm:ss"),
      duration: values.duration,
      totalStudents: 0,
      selectedClasses: values.selectedClasses || [],
      selectedCourses: values.selectedCourses || [],
      settings: {
        allowLateSubmission: values.allowLateSubmission,
        maxLateMinutes: values.maxLateMinutes || 0,
        allowReview: values.allowReview,
        autoGrade: values.autoGrade,
        requireProctor: values.requireProctor,
      },
    });

    setExams(examStore.getExams());
    setCreateExamModalVisible(false);
    examForm.resetFields();
    message.success("考试创建成功！");
  };

  const handleDeleteExam = (examId: string) => {
    Modal.confirm({
      title: "确认删除",
      content: "确定要删除这场考试吗？删除后无法恢复。",
      onOk: () => {
        examStore.deleteExam(examId);
        setExams(examStore.getExams());
        message.success("考试删除成功");
      },
    });
  };

  const handlePublishExamSubmit = () => {
    if (selectedExam) {
      examStore.publishExam(selectedExam.id);
      setExams(examStore.getExams());
      setPublishExamModalVisible(false);
      message.success("考试发布成功！");
    }
  };

  // 导出考试成绩
  const handleExportExamGrades = (exam: Exam) => {
    Modal.confirm({
      title: (
        <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
          <ExclamationCircleOutlined style={{ color: '#faad14' }} />
          <span>导出成绩</span>
        </div>
      ),
      content: "请选择导出方式：",
      cancelText: "取消",
      onCancel: () => Modal.destroyAll(),
      footer: [
        <Button key="cancel" onClick={() => Modal.destroyAll()}>
          取消
        </Button>,
        <Button 
          key="save" 
          type="primary" 
          onClick={() => {
            message.success("成绩已保存到成绩管理！");
            Modal.destroyAll();
          }}
          style={{ marginRight: '8px' }}
        >
          保存到成绩管理
        </Button>,
        <Button 
          key="export" 
          onClick={() => {
            // 模拟PDF导出过程
            message.loading("正在生成成绩单PDF...", 2).then(() => {
              // 创建下载链接
              const blob = new Blob([`考试成绩单：${exam.name}\n总人数：${exam.totalStudents}\n已提交：${exam.submittedCount}\n已批改：${exam.gradedCount}\n平均分：${exam.averageScore || 'N/A'}\n及格率：${exam.passRate || 'N/A'}%`], { 
                type: 'application/pdf' 
              });
              const url = window.URL.createObjectURL(blob);
              const link = document.createElement('a');
              link.href = url;
              link.download = `${exam.name}_成绩单.pdf`;
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);
              window.URL.revokeObjectURL(url);
              
              message.success("成绩单导出成功！文件已保存到下载文件夹");
              Modal.destroyAll();
            });
          }}
        >
          导出文件
        </Button>,
      ],
    });
  };

  // 成绩管理相关函数
  const handleGradeSubmission = (submission: ExamSubmission) => {
    setSelectedSubmission(submission);
    gradingForm.setFieldsValue({
      score: submission.score || 0,
      comments: submission.teacherComments || "",
    });
    setGradingModalVisible(true);
  };

  const handleBatchGrading = () => {
    setBatchGradingModalVisible(true);
  };

  // 导出学生答卷
  const handleExportSubmission = (submission: ExamSubmission) => {
    Modal.confirm({
      title: (
        <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
          <ExclamationCircleOutlined style={{ color: '#faad14' }} />
          <span>导出答卷</span>
        </div>
      ),
      content: "请选择导出方式：",
      cancelText: "取消",
      onCancel: () => Modal.destroyAll(),
      footer: [
        <Button key="cancel" onClick={() => Modal.destroyAll()}>
          取消
        </Button>,
        <Button 
          key="save" 
          type="primary" 
          onClick={() => {
            message.success("答卷已保存到成绩管理！");
            Modal.destroyAll();
          }}
          style={{ marginRight: '8px' }}
        >
          保存到成绩管理
        </Button>,
        <Button 
          key="export" 
          onClick={() => {
            // 模拟PDF导出过程
            message.loading("正在生成答卷PDF...", 2).then(() => {
              // 创建下载链接
              const blob = new Blob([`学生答卷：${submission.studentName}\n考试：${submission.examName}\n提交时间：${submission.submitTime}\n用时：${submission.timeSpent}分钟\n得分：${submission.score || '未批改'}/${submission.totalScore}\n状态：${submission.status === "published" ? "已发布" : submission.status === "graded" ? "已批改" : submission.status === "late" ? "逾期" : "已提交"}`], { 
                type: 'application/pdf' 
              });
              const url = window.URL.createObjectURL(blob);
              const link = document.createElement('a');
              link.href = url;
              link.download = `${submission.studentName}_${submission.examName}_答卷.pdf`;
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);
              window.URL.revokeObjectURL(url);
              
              message.success("答卷导出成功！文件已保存到下载文件夹");
              Modal.destroyAll();
            });
          }}
        >
          导出文件
        </Button>,
      ],
    });
  };

  // 统计数据
  const stats = examStore.getStatistics();

  return (
    <div style={{ padding: '24px' }}>
      {/* 统计卡片 */}
      <Row gutter={16} style={{ marginBottom: '24px' }}>
        <Col span={4}>
          <Card>
            <Statistic
              title="总试卷数"
              value={stats.totalPapers}
              prefix={<FileTextOutlined />}
              valueStyle={{ color: '#1890ff' }}
            />
          </Card>
        </Col>
        <Col span={4}>
          <Card>
            <Statistic
              title="已发布试卷"
              value={stats.publishedPapers}
              prefix={<CheckCircleOutlined />}
              valueStyle={{ color: '#52c41a' }}
            />
          </Card>
        </Col>
        <Col span={4}>
          <Card>
            <Statistic
              title="总考试数"
              value={stats.totalExams}
              prefix={<BookOutlined />}
              valueStyle={{ color: '#faad14' }}
            />
          </Card>
        </Col>
        <Col span={4}>
          <Card>
            <Statistic
              title="进行中考试"
              value={stats.ongoingExams}
              prefix={<ClockCircleOutlined />}
              valueStyle={{ color: '#722ed1' }}
            />
          </Card>
        </Col>
        <Col span={4}>
          <Card>
            <Statistic
              title="总提交数"
              value={stats.totalSubmissions}
              prefix={<TeamOutlined />}
              valueStyle={{ color: '#13c2c2' }}
            />
          </Card>
        </Col>
        <Col span={4}>
          <Card>
            <Statistic
              title="已批改数"
              value={stats.gradedSubmissions}
              prefix={<TrophyOutlined />}
              valueStyle={{ color: '#eb2f96' }}
            />
          </Card>
        </Col>
      </Row>

      {/* 主要内容区域 */}
      <Card>
        <Tabs activeKey={activeTab} onChange={setActiveTab}>
          {/* 试卷管理 */}
          <TabPane tab="试卷管理" key="papers">
            <div style={{ marginBottom: '16px' }}>
              <Row gutter={16} align="middle">
                <Col span={6}>
                  <Search
                    placeholder="搜索试卷名称或代码"
                    value={searchText}
                    onChange={(e) => setSearchText(e.target.value)}
                  />
                </Col>
                <Col span={3}>
                  <Select
                    placeholder="状态"
                    value={statusFilter}
                    onChange={setStatusFilter}
                    style={{ width: '100%' }}
                  >
                    <Option value="all">全部状态</Option>
                    <Option value="draft">草稿</Option>
                    <Option value="published">已发布</Option>
                    <Option value="archived">已归档</Option>
                  </Select>
                </Col>
                <Col span={3}>
                  <Select
                    placeholder="课程"
                    value={courseFilter}
                    onChange={setCourseFilter}
                    style={{ width: '100%' }}
                  >
                    <Option value="all">全部课程</Option>
                    <Option value="c1">数据结构与算法</Option>
                    <Option value="c2">Java程序设计</Option>
                    <Option value="c3">数据库原理</Option>
                  </Select>
                </Col>
                <Col span={3}>
                  <Button icon={<ReloadOutlined />} onClick={loadData}>
                    刷新
                  </Button>
                </Col>
                <Col span={3}>
                  <Button type="primary" icon={<PlusOutlined />} onClick={handleCreatePaper}>
                    新建试卷
                  </Button>
                </Col>
                <Col span={6}>
                  <Space>
                    <Button icon={<ImportOutlined />}>导入</Button>
                    <Button icon={<ExportOutlined />}>导出</Button>
                  </Space>
                </Col>
              </Row>
            </div>

            <Table
              columns={[
                {
                  title: "试卷信息",
                  key: "paperInfo",
                  render: (_, record) => (
                    <div>
                      <div style={{ fontWeight: 'bold', fontSize: '16px' }}>
                        {record.name}
                        {record.isTemplate && <Tag color="blue" style={{ marginLeft: 8 }}>模板</Tag>}
                      </div>
                      <div style={{ color: '#666', fontSize: '14px' }}>
                        {record.code} | {record.courseName}
                      </div>
                      <div style={{ color: '#999', fontSize: '12px' }}>
                        {record.description}
                      </div>
                      <div style={{ marginTop: 4 }}>
                        {record.tags.map(tag => (
                          <Tag key={tag} style={{ marginRight: 4, marginBottom: 2, fontSize: '11px' }}>
                            {tag}
                          </Tag>
                        ))}
                      </div>
                    </div>
                  ),
                },
                {
                  title: "基本信息",
                  key: "basicInfo",
                  render: (_, record) => (
                    <div>
                      <div>总分: {record.totalScore}分</div>
                      <div>时长: {record.duration}分钟</div>
                      <div>题数: {record.questionCount}题</div>
                      <div>难度: 
                        <Tag color={record.difficulty === "简单" ? "green" : record.difficulty === "中等" ? "orange" : "red"}>
                          {record.difficulty}
                        </Tag>
                      </div>
                    </div>
                  ),
                },
                {
                  title: "使用情况",
                  key: "usage",
                  render: (_, record) => (
                    <div>
                      <div>使用次数: {record.usageCount}</div>
                      {record.averageScore && (
                        <div>平均分: {record.averageScore}分</div>
                      )}
                      {record.passRate && (
                        <div>及格率: {record.passRate}%</div>
                      )}
                    </div>
                  ),
                },
                {
                  title: "状态",
                  dataIndex: "status",
                  key: "status",
                  render: (status: string) => (
                    <Tag color={status === "published" ? "green" : status === "draft" ? "orange" : "default"}>
                      {status === "published" ? "已发布" : status === "draft" ? "草稿" : "已归档"}
                    </Tag>
                  ),
                },
                {
                  title: "操作",
                  key: "actions",
                  render: (_, record) => (
                    <Space size="small">
                      <Button 
                        type="link" 
                        size="small" 
                        icon={<EyeOutlined />}
                        onClick={() => {
                          setSelectedPaper(record);
                          setPaperDetailVisible(true);
                        }}
                      >
                        查看
                      </Button>
                      <Button 
                        type="link" 
                        size="small" 
                        icon={<EditOutlined />}
                        onClick={() => handleEditPaper(record)}
                      >
                        编辑
                      </Button>
                      <Dropdown
                        overlay={
                          <Menu>
                            <Menu.Item key="copy" icon={<CopyOutlined />}>
                              复制试卷
                            </Menu.Item>
                            <Menu.Item key="export" icon={<DownloadOutlined />} onClick={() => handleExportPaper(record)}>
                              导出试卷
                            </Menu.Item>
                            <Menu.Item key="template" icon={<FileTextOutlined />}>
                              {record.isTemplate ? "取消模板" : "设为模板"}
                            </Menu.Item>
                            <Menu.Divider />
                            <Menu.Item key="delete" icon={<DeleteOutlined />} danger onClick={() => handleDeletePaper(record.id)}>
                              删除试卷
                            </Menu.Item>
                          </Menu>
                        }
                        trigger={['click']}
                      >
                        <Button type="link" size="small" icon={<MoreOutlined />} />
                      </Dropdown>
                    </Space>
                  ),
                },
              ]}
              dataSource={papers}
              rowKey="id"
              loading={loading}
              pagination={{
                total: papers.length,
                pageSize: 10,
                showSizeChanger: true,
                showQuickJumper: true,
                showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，共 ${total} 条`,
              }}
            />
          </TabPane>

          {/* 考试管理 */}
          <TabPane tab="考试管理" key="exams">
            <div style={{ marginBottom: '16px' }}>
              <Row gutter={16} align="middle">
                <Col span={6}>
                  <Search
                    placeholder="搜索考试名称"
                    value={searchText}
                    onChange={(e) => setSearchText(e.target.value)}
                  />
                </Col>
                <Col span={3}>
                  <Select
                    placeholder="状态"
                    value={statusFilter}
                    onChange={setStatusFilter}
                    style={{ width: '100%' }}
                  >
                    <Option value="all">全部状态</Option>
                    <Option value="draft">草稿</Option>
                    <Option value="published">已发布</Option>
                    <Option value="ongoing">进行中</Option>
                    <Option value="ended">已结束</Option>
                    <Option value="graded">已批改</Option>
                  </Select>
                </Col>
                <Col span={3}>
                  <Button icon={<ReloadOutlined />} onClick={loadData}>
                    刷新
                  </Button>
                </Col>
                <Col span={3}>
                  <Button type="primary" icon={<PlusOutlined />} onClick={handleCreateExam}>
                    新建考试
                  </Button>
                </Col>
                <Col span={9}>
                  <Space>
                    <Button icon={<RobotOutlined />}>AI批改</Button>
                    <Button icon={<ExportOutlined />}>导出成绩</Button>
                    <Button icon={<BarChartOutlined />}>成绩分析</Button>
                  </Space>
                </Col>
              </Row>
            </div>

            <Table
              columns={[
                {
                  title: "考试信息",
                  key: "examInfo",
                  render: (_, record) => (
                    <div>
                      <div style={{ fontWeight: 'bold', fontSize: '16px' }}>
                        {record.name}
                      </div>
                      <div style={{ color: '#666', fontSize: '14px' }}>
                        {record.paperName} | {record.courseName}
                      </div>
                      <div style={{ color: '#999', fontSize: '12px' }}>
                        {record.startTime} - {record.endTime}
                      </div>
                    </div>
                  ),
                },
                {
                  title: "考试状态",
                  key: "examStatus",
                  render: (_, record) => (
                    <div>
                      <div>
                        <Tag color={
                          record.status === "published" ? "green" : 
                          record.status === "ongoing" ? "blue" : 
                          record.status === "ended" ? "orange" : 
                          record.status === "graded" ? "purple" : "default"
                        }>
                          {record.status === "published" ? "已发布" : 
                           record.status === "ongoing" ? "进行中" : 
                           record.status === "ended" ? "已结束" : 
                           record.status === "graded" ? "已批改" : "草稿"}
                        </Tag>
                      </div>
                      <div style={{ fontSize: '12px', color: '#666', marginTop: 4 }}>
                        时长: {record.duration}分钟
                      </div>
                    </div>
                  ),
                },
                {
                  title: "参与情况",
                  key: "participation",
                  render: (_, record) => (
                    <div>
                      <div>总人数: {record.totalStudents}人</div>
                      <div>已提交: {record.submittedCount}人</div>
                      <div>已批改: {record.gradedCount}人</div>
                      <Progress 
                        percent={Math.round((record.submittedCount / record.totalStudents) * 100)} 
                        size="small" 
                        style={{ marginTop: 4 }}
                      />
                    </div>
                  ),
                },
                {
                  title: "成绩统计",
                  key: "scoreStats",
                  render: (_, record) => (
                    <div>
                      {record.averageScore && (
                        <div>平均分: {record.averageScore}分</div>
                      )}
                      {record.passRate && (
                        <div>及格率: {record.passRate}%</div>
                      )}
                    </div>
                  ),
                },
                {
                  title: "操作",
                  key: "actions",
                  render: (_, record) => (
                    <Space size="small">
                      <Button 
                        type="link" 
                        size="small" 
                        icon={<EyeOutlined />}
                        onClick={() => {
                          setSelectedExam(record);
                          setExamDetailVisible(true);
                        }}
                      >
                        查看
                      </Button>
                      {record.status === "draft" && (
                        <Button 
                          type="link" 
                          size="small" 
                          icon={<SendOutlined />}
                          onClick={() => handlePublishExam(record)}
                        >
                          发布
                        </Button>
                      )}
                      <Dropdown
                        overlay={
                          <Menu>
                            <Menu.Item key="edit" icon={<EditOutlined />}>
                              编辑考试
                            </Menu.Item>
                            <Menu.Item key="copy" icon={<CopyOutlined />}>
                              复制考试
                            </Menu.Item>
                            <Menu.Item key="grade" icon={<CheckOutlined />}>
                              批改考试
                            </Menu.Item>
                            <Menu.Item key="export" icon={<DownloadOutlined />} onClick={() => handleExportExamGrades(record)}>
                              导出成绩
                            </Menu.Item>
                            <Menu.Divider />
                            <Menu.Item key="delete" icon={<DeleteOutlined />} danger onClick={() => handleDeleteExam(record.id)}>
                              删除考试
                            </Menu.Item>
                          </Menu>
                        }
                        trigger={['click']}
                      >
                        <Button type="link" size="small" icon={<MoreOutlined />} />
                      </Dropdown>
                    </Space>
                  ),
                },
              ]}
              dataSource={exams}
              rowKey="id"
              loading={loading}
              pagination={{
                total: exams.length,
                pageSize: 10,
                showSizeChanger: true,
                showQuickJumper: true,
                showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，共 ${total} 条`,
              }}
            />
          </TabPane>

          {/* 成绩管理 */}
          <TabPane tab="成绩管理" key="grades">
            <div style={{ marginBottom: '16px' }}>
              <Row gutter={16} align="middle">
                <Col span={6}>
                  <Search
                    placeholder="搜索学生姓名或学号"
                    value={searchText}
                    onChange={(e) => setSearchText(e.target.value)}
                  />
                </Col>
                <Col span={3}>
                  <Select
                    placeholder="状态"
                    value={statusFilter}
                    onChange={setStatusFilter}
                    style={{ width: '100%' }}
                  >
                    <Option value="all">全部状态</Option>
                    <Option value="submitted">已提交</Option>
                    <Option value="graded">已批改</Option>
                    <Option value="published">已发布</Option>
                    <Option value="late">逾期提交</Option>
                  </Select>
                </Col>
                <Col span={3}>
                  <Button icon={<ReloadOutlined />} onClick={loadData}>
                    刷新
                  </Button>
                </Col>
                <Col span={3}>
                  <Button type="primary" icon={<RobotOutlined />} onClick={handleBatchGrading}>
                    AI批改
                  </Button>
                </Col>
                <Col span={9}>
                  <Space>
                    <Button icon={<ExportOutlined />}>导出成绩</Button>
                    <Button icon={<BarChartOutlined />}>成绩分析</Button>
                    <Button icon={<SendOutlined />}>发布成绩</Button>
                  </Space>
                </Col>
              </Row>
            </div>

            <Table
              columns={[
                {
                  title: "学生信息",
                  key: "studentInfo",
                  render: (_, record) => (
                    <div style={{ display: 'flex', alignItems: 'center' }}>
                      <Avatar style={{ marginRight: 8 }}>{record.studentName.charAt(0)}</Avatar>
                      <div>
                        <div style={{ fontWeight: 'bold' }}>{record.studentName}</div>
                        <div style={{ fontSize: '12px', color: '#666' }}>
                          {record.studentId} | {record.className}
                        </div>
                      </div>
                    </div>
                  ),
                },
                {
                  title: "考试信息",
                  key: "examInfo",
                  render: (_, record) => (
                    <div>
                      <div style={{ fontWeight: 'bold' }}>{record.examName}</div>
                      <div style={{ fontSize: '12px', color: '#666' }}>
                        提交时间: {record.submitTime}
                      </div>
                      <div style={{ fontSize: '12px', color: '#666' }}>
                        用时: {record.timeSpent}分钟
                      </div>
                    </div>
                  ),
                },
                {
                  title: "成绩",
                  key: "score",
                  render: (_, record) => (
                    <div>
                      {record.score ? (
                        <div>
                          <div style={{ fontSize: '16px', fontWeight: 'bold', color: '#1890ff' }}>
                            {record.score}/{record.totalScore}
                          </div>
                          <div style={{ fontSize: '12px', color: '#666' }}>
                            {record.aiScore && `AI评分: ${record.aiScore}分`}
                          </div>
                        </div>
                      ) : (
                        <div style={{ color: '#999' }}>未批改</div>
                      )}
                    </div>
                  ),
                },
                {
                  title: "状态",
                  key: "status",
                  render: (_, record) => (
                    <div>
                      <Tag color={
                        record.status === "published" ? "green" : 
                        record.status === "graded" ? "blue" : 
                        record.status === "late" ? "red" : "orange"
                      }>
                        {record.status === "published" ? "已发布" : 
                         record.status === "graded" ? "已批改" : 
                         record.status === "late" ? "逾期" : "已提交"}
                      </Tag>
                      {record.status === "late" && (
                        <div style={{ fontSize: '11px', color: '#f5222d', marginTop: 2 }}>
                          逾期提交
                        </div>
                      )}
                    </div>
                  ),
                },
                {
                  title: "批改信息",
                  key: "gradingInfo",
                  render: (_, record) => (
                    <div>
                      {record.gradedBy && (
                        <div>批改人: {record.gradedBy}</div>
                      )}
                      {record.gradedTime && (
                        <div style={{ fontSize: '12px', color: '#666' }}>
                          {record.gradedTime}
                        </div>
                      )}
                    </div>
                  ),
                },
                {
                  title: "操作",
                  key: "actions",
                  render: (_, record) => (
                    <Space size="small">
                      <Button 
                        type="link" 
                        size="small" 
                        icon={<EyeOutlined />}
                        onClick={() => handleGradeSubmission(record)}
                      >
                        查看
                      </Button>
                      {record.status !== "graded" && record.status !== "published" && (
                        <Button 
                          type="link" 
                          size="small" 
                          icon={<CheckOutlined />}
                          onClick={() => handleGradeSubmission(record)}
                        >
                          批改
                        </Button>
                      )}
                      <Dropdown
                        overlay={
                          <Menu>
                            <Menu.Item key="regrade" icon={<RollbackOutlined />}>
                              重新批改
                            </Menu.Item>
                            <Menu.Item key="comments" icon={<MessageOutlined />}>
                              添加评语
                            </Menu.Item>
                            <Menu.Item key="export" icon={<DownloadOutlined />} onClick={() => handleExportSubmission(record)}>
                              导出答卷
                            </Menu.Item>
                          </Menu>
                        }
                        trigger={['click']}
                      >
                        <Button type="link" size="small" icon={<MoreOutlined />} />
                      </Dropdown>
                    </Space>
                  ),
                },
              ]}
              dataSource={submissions}
              rowKey="id"
              loading={loading}
              pagination={{
                total: submissions.length,
                pageSize: 10,
                showSizeChanger: true,
                showQuickJumper: true,
                showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，共 ${total} 条`,
              }}
            />
          </TabPane>
        </Tabs>
      </Card>

      {/* 试卷详情弹窗 */}
      <Modal
        title="试卷详情"
        visible={paperDetailVisible}
        onCancel={() => setPaperDetailVisible(false)}
        footer={[
          <Button key="close" onClick={() => setPaperDetailVisible(false)}>
            关闭
          </Button>,
          <Button key="edit" type="primary" onClick={() => {
            setPaperDetailVisible(false);
            if (selectedPaper) handleEditPaper(selectedPaper);
          }}>
            编辑试卷
          </Button>,
        ]}
        width={800}
      >
        {selectedPaper && (
          <div>
            <Descriptions column={2} bordered>
              <Descriptions.Item label="试卷名称">{selectedPaper.name}</Descriptions.Item>
              <Descriptions.Item label="试卷代码">{selectedPaper.code}</Descriptions.Item>
              <Descriptions.Item label="所属课程">{selectedPaper.courseName}</Descriptions.Item>
              <Descriptions.Item label="总分">{selectedPaper.totalScore}分</Descriptions.Item>
              <Descriptions.Item label="考试时长">{selectedPaper.duration}分钟</Descriptions.Item>
              <Descriptions.Item label="题目数量">{selectedPaper.questionCount}题</Descriptions.Item>
              <Descriptions.Item label="难度等级">
                <Tag color={selectedPaper.difficulty === "简单" ? "green" : selectedPaper.difficulty === "中等" ? "orange" : "red"}>
                  {selectedPaper.difficulty}
                </Tag>
              </Descriptions.Item>
              <Descriptions.Item label="试卷状态">
                <Tag color={selectedPaper.status === "published" ? "green" : selectedPaper.status === "draft" ? "orange" : "default"}>
                  {selectedPaper.status === "published" ? "已发布" : selectedPaper.status === "draft" ? "草稿" : "已归档"}
                </Tag>
              </Descriptions.Item>
              <Descriptions.Item label="创建时间">{selectedPaper.createTime}</Descriptions.Item>
              <Descriptions.Item label="更新时间">{selectedPaper.updateTime}</Descriptions.Item>
              <Descriptions.Item label="创建者">{selectedPaper.creator}</Descriptions.Item>
              <Descriptions.Item label="使用次数">{selectedPaper.usageCount}次</Descriptions.Item>
            </Descriptions>
            
            <Divider />
            
            <Title level={4}>试卷描述</Title>
            <Text>{selectedPaper.description}</Text>
            
            <Divider />
            
            <Title level={4}>试卷标签</Title>
            <div>
              {selectedPaper.tags.map(tag => (
                <Tag key={tag} style={{ marginBottom: 8 }}>{tag}</Tag>
              ))}
            </div>
            
            {selectedPaper.averageScore && (
              <>
                <Divider />
                <Title level={4}>使用统计</Title>
                <Row gutter={16}>
                  <Col span={8}>
                    <Statistic title="平均分" value={selectedPaper.averageScore} suffix="分" />
                  </Col>
                  <Col span={8}>
                    <Statistic title="及格率" value={selectedPaper.passRate} suffix="%" />
                  </Col>
                  <Col span={8}>
                    <Statistic title="使用次数" value={selectedPaper.usageCount} />
                  </Col>
                </Row>
              </>
            )}
          </div>
        )}
      </Modal>

      {/* 创建试卷弹窗 */}
      <Modal
        title="创建试卷"
        visible={createPaperModalVisible}
        onOk={() => {
          paperForm.validateFields().then(values => {
            const newPaper: ExamPaper = {
              id: `p${Date.now()}`,
              name: values.name,
              code: values.code,
              courseId: values.courseId,
              courseName: "数据结构与算法", // 这里应该根据courseId获取
              totalScore: values.totalScore,
              duration: values.duration,
              questionCount: 0, // 需要根据题目数量计算
              difficulty: values.difficulty,
              status: "draft",
              createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
              updateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
              creator: "张教授",
              description: values.description,
              tags: values.tags || [],
              isTemplate: false,
              usageCount: 0,
            };
            setPapers(prev => [...prev, newPaper]);
            setCreatePaperModalVisible(false);
            paperForm.resetFields();
            message.success("试卷创建成功");
          });
        }}
        onCancel={() => {
          setCreatePaperModalVisible(false);
          paperForm.resetFields();
        }}
        width={600}
      >
        <Form form={paperForm} layout="vertical">
          <Form.Item name="name" label="试卷名称" rules={[{ required: true, message: "请输入试卷名称" }]}>
            <Input placeholder="请输入试卷名称" />
          </Form.Item>
          <Form.Item name="code" label="试卷代码" rules={[{ required: true, message: "请输入试卷代码" }]}>
            <Input placeholder="请输入试卷代码" />
          </Form.Item>
          <Form.Item name="courseId" label="所属课程" rules={[{ required: true, message: "请选择所属课程" }]}>
            <Select placeholder="请选择课程">
              <Option value="c1">数据结构与算法</Option>
              <Option value="c2">Java程序设计</Option>
              <Option value="c3">数据库原理</Option>
            </Select>
          </Form.Item>
          <Row gutter={16}>
            <Col span={12}>
              <Form.Item name="totalScore" label="总分" rules={[{ required: true, message: "请输入总分" }]}>
                <InputNumber min={1} max={200} style={{ width: '100%' }} placeholder="请输入总分" />
              </Form.Item>
            </Col>
            <Col span={12}>
              <Form.Item name="duration" label="考试时长(分钟)" rules={[{ required: true, message: "请输入考试时长" }]}>
                <InputNumber min={30} max={300} style={{ width: '100%' }} placeholder="请输入时长" />
              </Form.Item>
            </Col>
          </Row>
          <Form.Item name="difficulty" label="难度等级" rules={[{ required: true, message: "请选择难度等级" }]}>
            <Select placeholder="请选择难度等级">
              <Option value="简单">简单</Option>
              <Option value="中等">中等</Option>
              <Option value="困难">困难</Option>
            </Select>
          </Form.Item>
          <Form.Item name="description" label="试卷描述">
            <TextArea rows={3} placeholder="请输入试卷描述" />
          </Form.Item>
          <Form.Item name="tags" label="试卷标签">
            <Select mode="tags" placeholder="请输入标签">
              <Option value="期中考试">期中考试</Option>
              <Option value="期末考试">期末考试</Option>
              <Option value="实验考试">实验考试</Option>
            </Select>
          </Form.Item>
        </Form>
      </Modal>

      {/* 考试详情弹窗 */}
      <Modal
        title="考试详情"
        visible={examDetailVisible}
        onCancel={() => setExamDetailVisible(false)}
        footer={[
          <Button key="close" onClick={() => setExamDetailVisible(false)}>
            关闭
          </Button>,
          <Button key="grade" type="primary" onClick={() => {
            setExamDetailVisible(false);
            navigate("/teacher/exam-grading");
          }}>
            批改考试
          </Button>,
        ]}
        width={800}
      >
        {selectedExam && (
          <div>
            <Descriptions column={2} bordered>
              <Descriptions.Item label="考试名称">{selectedExam.name}</Descriptions.Item>
              <Descriptions.Item label="试卷名称">{selectedExam.paperName}</Descriptions.Item>
              <Descriptions.Item label="所属课程">{selectedExam.courseName}</Descriptions.Item>
              <Descriptions.Item label="考试状态">
                <Tag color={
                  selectedExam.status === "published" ? "green" : 
                  selectedExam.status === "ongoing" ? "blue" : 
                  selectedExam.status === "ended" ? "orange" : 
                  selectedExam.status === "graded" ? "purple" : "default"
                }>
                  {selectedExam.status === "published" ? "已发布" : 
                   selectedExam.status === "ongoing" ? "进行中" : 
                   selectedExam.status === "ended" ? "已结束" : 
                   selectedExam.status === "graded" ? "已批改" : "草稿"}
                </Tag>
              </Descriptions.Item>
              <Descriptions.Item label="开始时间">{selectedExam.startTime}</Descriptions.Item>
              <Descriptions.Item label="结束时间">{selectedExam.endTime}</Descriptions.Item>
              <Descriptions.Item label="考试时长">{selectedExam.duration}分钟</Descriptions.Item>
              <Descriptions.Item label="创建时间">{selectedExam.createTime}</Descriptions.Item>
            </Descriptions>
            
            <Divider />
            
            <Title level={4}>参与情况</Title>
            <Row gutter={16}>
              <Col span={6}>
                <Statistic title="总人数" value={selectedExam.totalStudents} />
              </Col>
              <Col span={6}>
                <Statistic title="已提交" value={selectedExam.submittedCount} />
              </Col>
              <Col span={6}>
                <Statistic title="已批改" value={selectedExam.gradedCount} />
              </Col>
              <Col span={6}>
                <Statistic 
                  title="提交率" 
                  value={Math.round((selectedExam.submittedCount / selectedExam.totalStudents) * 100)} 
                  suffix="%" 
                />
              </Col>
            </Row>
            
            {selectedExam.averageScore && (
              <>
                <Divider />
                <Title level={4}>成绩统计</Title>
                <Row gutter={16}>
                  <Col span={8}>
                    <Statistic title="平均分" value={selectedExam.averageScore} suffix="分" />
                  </Col>
                  <Col span={8}>
                    <Statistic title="及格率" value={selectedExam.passRate} suffix="%" />
                  </Col>
                  <Col span={8}>
                    <Statistic title="最高分" value={95} suffix="分" />
                  </Col>
                </Row>
              </>
            )}
            
            <Divider />
            
            <Title level={4}>考试设置</Title>
            <Descriptions column={2} size="small">
              <Descriptions.Item label="允许逾期提交">
                {selectedExam.settings.allowLateSubmission ? "是" : "否"}
              </Descriptions.Item>
              <Descriptions.Item label="最大逾期时间">
                {selectedExam.settings.maxLateMinutes}分钟
              </Descriptions.Item>
              <Descriptions.Item label="允许查看答案">
                {selectedExam.settings.allowReview ? "是" : "否"}
              </Descriptions.Item>
              <Descriptions.Item label="自动批改">
                {selectedExam.settings.autoGrade ? "是" : "否"}
              </Descriptions.Item>
              <Descriptions.Item label="需要监考">
                {selectedExam.settings.requireProctor ? "是" : "否"}
              </Descriptions.Item>
            </Descriptions>
          </div>
        )}
      </Modal>

      {/* 批改弹窗 */}
      <Modal
        title="批改试卷"
        visible={gradingModalVisible}
        onOk={() => {
          gradingForm.validateFields().then(values => {
            if (selectedSubmission) {
              const updatedSubmission = {
                ...selectedSubmission,
                score: values.score,
                teacherComments: values.comments,
                status: "graded" as const,
                gradedBy: "张教授",
                gradedTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
              };
              setSubmissions(prev => prev.map(s => 
                s.id === selectedSubmission.id ? updatedSubmission : s
              ));
              setGradingModalVisible(false);
              gradingForm.resetFields();
              message.success("批改完成");
            }
          });
        }}
        onCancel={() => {
          setGradingModalVisible(false);
          gradingForm.resetFields();
        }}
        width={600}
      >
        {selectedSubmission && (
          <div>
            <Descriptions column={2} size="small" style={{ marginBottom: 16 }}>
              <Descriptions.Item label="学生姓名">{selectedSubmission.studentName}</Descriptions.Item>
              <Descriptions.Item label="学号">{selectedSubmission.studentId}</Descriptions.Item>
              <Descriptions.Item label="考试名称">{selectedSubmission.examName}</Descriptions.Item>
              <Descriptions.Item label="提交时间">{selectedSubmission.submitTime}</Descriptions.Item>
              <Descriptions.Item label="用时">{selectedSubmission.timeSpent}分钟</Descriptions.Item>
              <Descriptions.Item label="总分">{selectedSubmission.totalScore}分</Descriptions.Item>
            </Descriptions>
            
            {selectedSubmission.aiScore && (
              <Alert
                message="AI批改结果"
                description={`AI评分: ${selectedSubmission.aiScore}分 | ${selectedSubmission.aiComments}`}
                type="info"
                style={{ marginBottom: 16 }}
              />
            )}
            
            <Form form={gradingForm} layout="vertical">
              <Form.Item 
                name="score" 
                label="评分" 
                rules={[{ required: true, message: "请输入评分" }]}
              >
                <InputNumber 
                  min={0} 
                  max={selectedSubmission.totalScore} 
                  style={{ width: '100%' }} 
                  placeholder="请输入评分" 
                />
              </Form.Item>
              <Form.Item name="comments" label="评语">
                <TextArea rows={4} placeholder="请输入评语" />
              </Form.Item>
            </Form>
          </div>
        )}
      </Modal>

      {/* 创建考试弹窗 */}
      <Modal
        title="创建考试"
        visible={createExamModalVisible}
        onOk={() => examForm.submit()}
        onCancel={() => {
          setCreateExamModalVisible(false);
          examForm.resetFields();
        }}
        width={800}
      >
        <Form form={examForm} layout="vertical" onFinish={handleCreateExamSubmit}>
          <Row gutter={16}>
            <Col span={12}>
              <Form.Item 
                name="name" 
                label="考试名称" 
                rules={[{ required: true, message: "请输入考试名称" }]}
              >
                <Input placeholder="请输入考试名称" />
              </Form.Item>
            </Col>
            <Col span={12}>
              <Form.Item 
                name="paperId" 
                label="选择试卷" 
                rules={[{ required: true, message: "请选择试卷" }]}
              >
                <Select placeholder="请选择试卷">
                  {papers.map(paper => (
                    <Option key={paper.id} value={paper.id}>
                      {paper.name} ({paper.totalScore}分)
                    </Option>
                  ))}
                </Select>
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={12}>
              <Form.Item 
                name="courseId" 
                label="选择课程" 
                rules={[{ required: true, message: "请选择课程" }]}
              >
                <Select 
                  placeholder="请选择课程"
                  onChange={(value) => {
                    const course = COURSES.find(c => c.id === value);
                    examForm.setFieldsValue({ courseName: course?.name });
                  }}
                >
                  {COURSES.map(course => (
                    <Option key={course.id} value={course.id}>
                      {course.name}
                    </Option>
                  ))}
                </Select>
              </Form.Item>
            </Col>
            <Col span={12}>
              <Form.Item name="courseName" label="课程名称">
                <Input disabled style={{ backgroundColor: '#f5f5f5' }} />
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={12}>
              <Form.Item 
                name="startTime" 
                label="开始时间" 
                rules={[{ required: true, message: "请选择开始时间" }]}
              >
                <DatePicker 
                  showTime={{ format: 'HH:mm' }}
                  format="YYYY-MM-DD HH:mm"
                  style={{ width: '100%' }}
                  placeholder="请选择开始时间"
                />
              </Form.Item>
            </Col>
            <Col span={12}>
              <Form.Item 
                name="endTime" 
                label="结束时间" 
                rules={[{ required: true, message: "请选择结束时间" }]}
              >
                <DatePicker 
                  showTime={{ format: 'HH:mm' }}
                  format="YYYY-MM-DD HH:mm"
                  style={{ width: '100%' }}
                  placeholder="请选择结束时间"
                />
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={12}>
              <Form.Item 
                name="duration" 
                label="考试时长(分钟)" 
                rules={[{ required: true, message: "请输入考试时长" }]}
              >
                <InputNumber 
                  min={30} 
                  max={300} 
                  style={{ width: '100%' }} 
                  placeholder="请输入考试时长" 
                />
              </Form.Item>
            </Col>
            <Col span={12}>
              <Form.Item 
                name="selectedClasses" 
                label="选择班级"
              >
                <Select 
                  mode="multiple" 
                  placeholder="请选择班级"
                  showSearch
                  optionFilterProp="children"
                >
                  {CLASSES.map(cls => (
                    <Option key={cls.id} value={cls.id}>
                      {cls.name} ({cls.studentCount}人)
                    </Option>
                  ))}
                </Select>
              </Form.Item>
            </Col>
          </Row>

          <Divider>考试设置</Divider>

          <Row gutter={16}>
            <Col span={8}>
              <Form.Item 
                name="allowLateSubmission" 
                label="允许逾期提交"
                valuePropName="checked"
              >
                <Switch />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item 
                name="allowReview" 
                label="允许查看答案"
                valuePropName="checked"
              >
                <Switch />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item 
                name="autoGrade" 
                label="自动批改"
                valuePropName="checked"
              >
                <Switch />
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={8}>
              <Form.Item 
                name="requireProctor" 
                label="需要监考"
                valuePropName="checked"
              >
                <Switch />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item 
                name="maxLateMinutes" 
                label="最大逾期时间(分钟)"
              >
                <InputNumber 
                  min={0} 
                  max={60} 
                  style={{ width: '100%' }} 
                  placeholder="逾期时间" 
                />
              </Form.Item>
            </Col>
          </Row>
        </Form>
      </Modal>

      {/* 发布考试弹窗 */}
      <Modal
        title="发布考试"
        visible={publishExamModalVisible}
        onOk={handlePublishExamSubmit}
        onCancel={() => setPublishExamModalVisible(false)}
        width={600}
      >
        {selectedExam && (
          <div>
            <Alert
              message="确认发布"
              description="发布后学生将可以参加考试，确定要发布吗？"
              type="warning"
              style={{ marginBottom: 16 }}
            />
            
            <Descriptions column={1} size="small">
              <Descriptions.Item label="考试名称">{selectedExam.name}</Descriptions.Item>
              <Descriptions.Item label="试卷名称">{selectedExam.paperName}</Descriptions.Item>
              <Descriptions.Item label="课程名称">{selectedExam.courseName}</Descriptions.Item>
              <Descriptions.Item label="开始时间">{selectedExam.startTime}</Descriptions.Item>
              <Descriptions.Item label="结束时间">{selectedExam.endTime}</Descriptions.Item>
              <Descriptions.Item label="考试时长">{selectedExam.duration}分钟</Descriptions.Item>
              <Descriptions.Item label="参与班级">
                {selectedExam.selectedClasses?.length > 0 
                  ? CLASSES.filter(cls => selectedExam.selectedClasses.includes(cls.id))
                      .map(cls => cls.name).join(", ")
                  : "未选择班级"
                }
              </Descriptions.Item>
            </Descriptions>
          </div>
        )}
      </Modal>
    </div>
  );
};

export default ExamManagement; 